﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using METU_CMT.Business;

namespace METU_CMT
{
    public partial class DownloadReviewTeamsDocumentsScreen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindReviewTeamsDocuments();
            }
        }

        private void BindReviewTeamsDocuments()
        {
            Student _student = (Student) EntityFactory.User;
            Course _currentCourse = EntityFactory.GetCurrentCourse(UserType.Student);

            List< LocalEventDocument > _localEventDocuments;
            _currentCourse.GetStudentsReviewTeamAssigments( _student, out _localEventDocuments );

            dtgDocuments.DataSource = _localEventDocuments;
            dtgDocuments.DataBind();
        }

        protected void OnLnkBtnDownloadClicked(object sender, EventArgs e)
        {
            GridViewRow _gridViewRow = (GridViewRow)((LinkButton)sender).NamingContainer;
            int _teamId = CommonMethods.GetIdFromGridViewRow(_gridViewRow);

            HiddenField _hfEventId = (HiddenField)_gridViewRow.FindControl("hfEventId");
            int _eventId;
            if(int.TryParse(_hfEventId.Value, out _eventId) == false )
            {
                return;
            }

            Team _team = new Team(_teamId);
            _team.DownloadDeliverable(new Event( _eventId ));

        }

        protected void OnlnkBtnDownloadAllDocumentsClicked(object sender, EventArgs e)
        {
            //TODO: Do download document for all gridview rows.
        }

    }
}